package com.example.mybatis.mapper;

import com.example.mybatis.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    // 根据id删除数据
    @Delete("delete from emp where id = #{id}")
    public int deleteById(Integer id);

    //新增员工
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username,name,gender,image,job,entrydate,dept_id,create_time,update_time) " +
            "values(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    public int insert(Emp emp);

    @Update("update emp set " +
            "username=#{username},name=#{name},gender=#{gender},image=#{image},job=#{job}," +
            "entrydate=#{entrydate},dept_id=#{deptId},update_time=#{updateTime} where id=#{id}")
    public int update(Emp emp);


    @Select("select * from emp where id = #{id}")
    public Emp SelectById(Integer id);

    @Select("select *  from emp")
    public List<Emp> list();

    @Select("select * from emp where name like concat('%',#{name},'%') and gender = #{gender} and " +
            "entrydate between #{begin} and #{end} order by update_time desc")
    public List<Emp> listByDeptId(String name, Short gender, LocalDate begin, LocalDate end);


    public List<Emp> selectAll();

    public Emp selectById(Integer id);

    public List<Emp> list1(String name, Short gender, LocalDate begin, LocalDate end);

}
